


import grails.test.*

class PspDataTests extends GrailsUnitTestCase {
    protected void setUp() {
        super.setUp()
        mockDomain PspData
        mockForConstraintsTests(PspData)

        mockDomain User
        mockDomain Task
        mockDomain SubTask
        mockDomain Project

        def user = new User(username:"XXX",userRealName:"XXX",passwd:"XXX",email:"xxx@yyy.com")
        user.save(flush:true)

        def project = new Project(name:"Project1")
        project.save(flush:true)
        project = Project.findByName("Project1")
        
        def task = new Task(name:"LAB1")
        task.project = project
        task.save(flush:true)

        def subTasks = [
            new SubTask(phaseName: "Planning", estimatedTime: 20, finalTime: 10, task: task, unitForPhase: 3, dateCreated: new Date(), lastUpdated: new Date()),
            new SubTask(phaseName: "Design", estimatedTime: 20, finalTime: 10, task: task, unitForPhase: 3, dateCreated: new Date(), lastUpdated: new Date()),
            new SubTask(phaseName: "Code", estimatedTime: 20, finalTime: 10, task: task, unitForPhase: 3, dateCreated: new Date(), lastUpdated: new Date()),
            new SubTask(phaseName: "Compile", estimatedTime: 20, finalTime: 10, task: task, unitForPhase: 3, dateCreated: new Date(), lastUpdated: new Date()),
            new SubTask(phaseName: "Test", estimatedTime: 20, finalTime: 10, task: task, unitForPhase: 3, dateCreated: new Date(), lastUpdated: new Date()),
            new SubTask(phaseName: "Postmortem", estimatedTime: 20, finalTime: 10, task: task, unitForPhase: 3, dateCreated: new Date(), lastUpdated: new Date()),
        ]
        subTasks*.save(flush:true)
    }
	
    protected void tearDown() {
        super.tearDown()
    }
	
    void testCreationOfPspData() {
        def p = new PspData()
        assertFalse p.validate()

        def pspData = new PspData(phaseName:"Planning", startdate:new Date(), actualTimeInMin:10, interuptTimeInMin:5)
        pspData.user = User.findByUsername("XXX")
        pspData.task = Task.findByName("LAB1")

        assertNull pspData.save()
    }
	
    void testPspDataObjectValidation(){
        //
        //        def pspData = new PspData()
        //        pspData.phaseName = "Planning"
        //        pspData.startDate = new Date()
        //        pspData.actualTimeInMin = 10
        //        pspData.interuptTimeInMin = 5
        //
        //        assertTrue(false, pspData.validate())
    }
}
